#define _CRT_SECURE_NO_WARNINGS  1
#include<stdio.h>
#include<stdlib.h>
int cmp(const void* x, const void* y)
{
    return (*(int*)x - *(int*)y);
}
int a[1000];
int nums1[] = { 1 };
int nums2[] = { 1 };
int* intersection(int* nums1, int nums1Size, int* nums2, int nums2Size, int* returnSize)
{
    qsort(nums1, nums1Size, sizeof(int), cmp);
    qsort(nums2, nums2Size, sizeof(int), cmp);
    *returnSize = 0;
    for (int i = 0; i < nums1Size; i++)
    {
        if (i != 0 && nums1[i - 1] == nums1[i])
            continue;
        int left = 0;
        int right = nums2Size - 1;
        int mid = (left + right) / 2;
        while (left <= right)
        {
            if (nums1[i] < nums2[mid])
            {
                right = mid - 1;
                mid = (left + right) / 2;
            }
            else if (nums1[i] > nums2[mid])
            {
                left = mid + 1;
                mid = (left + right) / 2;
            }
            else
            {
                a[*returnSize] = nums1[i];
                (*returnSize)++;
                break;
            }
        }
    }
    return a;
}
int main()
{
    int len;
    intersection(nums1, sizeof(nums1)/sizeof(nums1[0]), nums2, sizeof(nums2) / sizeof(nums2[0]), &len);
    for (int i = 0; i < len; i++)
    {
        printf("%d ", a[i]);
    }
    return 0;
}